<?php
namespace App\Http\Controllers\desktop\publics;

use App\Models\Category;
use App\Models\Book;

class CategoryController extends BaseController {
	
	public function show($id) {
		$category = Category::find($id);
		if(is_null($category)) {
			return redirect('/404');
		}
		$books = Book::where('category_id', $category->id)
				->orderBy('clicks', 'DESC')
				->paginate(40);
		$hotBooks = Book::where('category_id', $category->id)
				->orderBy('likes', 'desc')->take(5)->get();
		return view('desktop.publics.category_books', compact('category', 'books', 'hotBooks'));
	}
}
